package com.trippin.DB.entities;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.google.gson.annotations.Expose;
import com.trippin.DB.entities.AttractionEntity.ShortDetailedAttraction;

public class UserSuggestion {
	
	@Expose
	private long userId;
	
	@Expose
	private int numOfTotalAttractions;
	
	@Expose
	private int numOfSameScheduleAttractions;
	
	@Expose
	private int numOfNotSameScheduleAttractions;
	
	@Expose
	private int numOfNotAttendScheduleAttractions;
	
	private int numOfSimilarAttractions;
	
	@Expose
	private Set<ScheduledAttractionEntity> similarAttractionsSchecule;
	
	@Expose
	private Set<ScheduledAttractionEntity> similarAttractionsNotSameSchecule;
	
	
	private Set<ShortDetailedAttraction> similarAttractionsNotScheduled;
	
	@Expose
	private Set<ScheduledAttractionEntity> notAttendScheduleAttractions;
	
	
	public UserSuggestion(long userId) {
		this.userId = userId;
		this.numOfTotalAttractions = 0;
		numOfSameScheduleAttractions = 0;
		numOfNotSameScheduleAttractions = 0;
		numOfSimilarAttractions = 0;
		similarAttractionsSchecule = new HashSet<ScheduledAttractionEntity>();
		similarAttractionsNotSameSchecule = new HashSet<ScheduledAttractionEntity>();		
		similarAttractionsNotScheduled = new HashSet<ShortDetailedAttraction>();
		notAttendScheduleAttractions = new HashSet<ScheduledAttractionEntity>();;
	}
	
	public long getUserId() {
		return userId;
	}

	public void setSimilarAttractionsSchecule(List<ScheduledAttractionEntity> similarScheduleAttrs) {
		if(similarAttractionsSchecule != null) {
			numOfTotalAttractions -= numOfSameScheduleAttractions;
		}
		similarAttractionsSchecule = new HashSet<ScheduledAttractionEntity>(similarScheduleAttrs);
		numOfSameScheduleAttractions = similarAttractionsSchecule.size();
		numOfTotalAttractions += numOfSameScheduleAttractions;
	}
	
	
	public void addSimilarAttractionSchecule(ScheduledAttractionEntity ScheduleAttr) {
		if(similarAttractionsSchecule == null) {
			similarAttractionsSchecule = new HashSet<ScheduledAttractionEntity>();
		}
		if(!similarAttractionsNotSameSchecule.contains(ScheduleAttr) && !similarAttractionsSchecule.contains(ScheduleAttr)) {
			similarAttractionsSchecule.add(ScheduleAttr);
			numOfSameScheduleAttractions++;
			numOfTotalAttractions++;
		}
	}
	
	public int getNumOfSameScheduleAttrs() {
		return numOfSameScheduleAttractions;
	}
	
	public void setSimilarAttractionsNotSameSchecule(List<ScheduledAttractionEntity> similarAttrsNotSameSchedule) {
		if(similarAttractionsNotSameSchecule != null) {
			numOfTotalAttractions -= numOfNotSameScheduleAttractions;
		}
		similarAttractionsNotSameSchecule = new HashSet<ScheduledAttractionEntity>(similarAttrsNotSameSchedule);
		numOfNotSameScheduleAttractions =  similarAttractionsNotSameSchecule.size();
		numOfTotalAttractions += numOfNotSameScheduleAttractions;
	}
	
	
	public void addSimilarAttractionNotSameSchecule(ScheduledAttractionEntity ScheduleAttr) {
		if(similarAttractionsNotSameSchecule == null) {
			similarAttractionsNotSameSchecule = new HashSet<ScheduledAttractionEntity>();
		}
		if(!similarAttractionsNotSameSchecule.contains(ScheduleAttr) && !similarAttractionsSchecule.contains(ScheduleAttr)) {
			similarAttractionsNotSameSchecule.add(ScheduleAttr);
			numOfNotSameScheduleAttractions++;
			numOfTotalAttractions++;
		}
	}
	
	public int getNumOfNotSameScheduleAttrs() {
		return numOfNotSameScheduleAttractions;
	}


	public void setSimilarAttractions(List<ShortDetailedAttraction> similarAttrs) {
		if(similarAttractionsNotScheduled != null) {
			numOfTotalAttractions -= numOfSimilarAttractions;
		}
		similarAttractionsNotScheduled = new HashSet<ShortDetailedAttraction>(similarAttrs);
		numOfSimilarAttractions = similarAttractionsSchecule.size();
		numOfTotalAttractions += numOfSimilarAttractions;
	}
	
	
	public void addSimilarAttraction(ShortDetailedAttraction Attr) {
		if(similarAttractionsNotScheduled == null) {
			similarAttractionsNotScheduled = new HashSet<ShortDetailedAttraction>();
		}
		if(!similarAttractionsNotScheduled.contains(Attr)) {
			similarAttractionsNotScheduled.add(Attr);
			numOfSimilarAttractions++;
			numOfTotalAttractions++;
		}
	}
	
	public int getNumOfSimilarAttrs() {
		return numOfSimilarAttractions;
	}
	
	public void addScheduleAttractionsNotAttend(ScheduledAttractionEntity ScheduleAttr) {
		if(notAttendScheduleAttractions == null) {
			notAttendScheduleAttractions = new HashSet<ScheduledAttractionEntity>();
		}
		if(!similarAttractionsNotSameSchecule.contains(ScheduleAttr) && !similarAttractionsSchecule.contains(ScheduleAttr)) {
			notAttendScheduleAttractions.add(ScheduleAttr);
			numOfNotAttendScheduleAttractions++;
			numOfTotalAttractions++;
		}
	}
	
	public int getNumOfNotAttendScheduleAttrs() {
		return numOfNotAttendScheduleAttractions;
	}
	
	public void setSNotAttendScheduleAttractions(List<ScheduledAttractionEntity> similarAttrsNotSameSchedule) {
		if(notAttendScheduleAttractions != null) {
			numOfTotalAttractions -= numOfNotAttendScheduleAttractions;
		}
		notAttendScheduleAttractions = new HashSet<ScheduledAttractionEntity>(similarAttrsNotSameSchedule);
		numOfNotAttendScheduleAttractions =  similarAttractionsNotSameSchecule.size();
		numOfTotalAttractions += numOfNotAttendScheduleAttractions;
	}
	
	
	public int getNumOfTotalAttractions() {
		return numOfTotalAttractions;
	}
	
	
	public boolean isAttractionAttended(long attrId) {
		for(ScheduledAttractionEntity sae : similarAttractionsSchecule) {
			if(sae.getAttrId() == attrId) {
				return true;
			}
		}
		
		for(ScheduledAttractionEntity sae : similarAttractionsNotSameSchecule) {
			if(sae.getAttrId() == attrId) {
				return true;
			}
		}
		
		for(ShortDetailedAttraction sda : similarAttractionsNotScheduled) {
			if(sda.getId() == attrId) {
				return true;
			}
		}
		
		return false;
	}
	

}